package com.gxa.autoparts.portal.controller;

import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.exception.BusinessException;
import com.gxa.autoparts.core.pojo.Advice;
import com.gxa.autoparts.core.pojo.SystemMessage;
import com.gxa.autoparts.portal.service.SystemMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ：looker
 * @date ：Created in 2022/1/8 14:09
 * 系统消息通知controller
 */
@RestController
@RequestMapping("/news")
@Api(tags = "消息控制器")
public class NewsController {

    @Autowired
    SystemMessageService systemMessageService;

    @PostMapping("/getNews")
    @ApiOperation("获取系统通知消息")
    public Map getNews(){
        Long userId = 1L;
        Map<String, Object> userMessageById = systemMessageService.getUserMessageById(userId);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(userMessageById);
        return jsonResult.getDataMap();
    }

    @PostMapping("/getNewsById")
    @ApiOperation("获取详细消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "消息Id",required = true,dataType = "long",paramType = "query")
    })
    public Map getNewInfo(Long id) throws BusinessException {
        Long userId = 1L;
        SystemMessage byId = systemMessageService.getById(id,userId);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(byId);
        return jsonResult.getDataMap();
    }


    @PostMapping("/delNewsById")
    public Map delNewsById(Long id) throws BusinessException {
        Long userId = 1L;
        systemMessageService.delMessage(id,userId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除"+id+"成功！");
        return jsonResult.getDataMap();
    }
}
